<template>
  <div class="action-sheet" @click="hideActionSheet">
    <ul class="action-sheet-list" :class="{ show: isShowList }">
      <li
        v-for="(item, index) in store.state.actionSheetConfig.list"
        :key="index"
        @click="clickHandler(index)"
        class="actionsItem"
      >
        <div class="left_icon">
          <svg class="icon" aria-hidden="true" v-if="index == 0">
            <use xlink:href="#icon-bofang1"></use>
          </svg>
          <svg class="icon" aria-hidden="true" v-if="index == 1">
            <use xlink:href="#icon-shoucang"></use>
          </svg>
          <svg class="icon" aria-hidden="true" v-if="index == 2">
            <use xlink:href="#icon-xiazai"></use>
          </svg>
          <svg class="icon" aria-hidden="true" v-if="index == 3">
            <use xlink:href="#icon-jianyi"></use>
          </svg>
          <svg class="icon" aria-hidden="true" v-if="index == 4">
            <use xlink:href="#icon-fenxiang"></use>
          </svg>
        </div>
        <div class="action">{{ item }}</div>
      </li>
      <li>取消</li>
    </ul>
  </div>
</template>

<script>
import { onMounted, ref } from "vue";
import { useStore } from "vuex";
export default {
  name: "ActionSheet",
  setup() {
    const store = useStore();
    function hideActionSheet() {
      store.commit("hideActionSheet");
    }
    function clickHandler(index) {
      if (typeof store.state.actionSheetConfig.successCallBack === "function") {
        store.state.actionSheetConfig.successCallBack(index);
      }
    }

    let isShowList = ref(false);
    onMounted(() => {
      setTimeout(() => {
        isShowList.value = true;
      }, 50);
    });

    return { store, hideActionSheet, clickHandler, isShowList };
  },
};
</script>

<style lang="less" scoped>
.action-sheet {
  background-color: rgba(0, 0, 0, 0.8);
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  .action-sheet-list {
    background-color: gray;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    transform: translateY(100%);
    transition: all 200ms linear;
    li {
      user-select: none;
      // height: 35px;
      width: 100%;
      padding: 5px 10px;
      display: flex;
      flex-flow: row;
      justify-content: center;
      align-items: center;
      background-color: #fff;
      // border-bottom: 1px solid lightgray;

      .left_icon {
        width: 35px;
        height: 35px;
        position: relative;
        .icon {
          position: absolute;
          width: 20px;
          height: 20px;
          left: 50%;
          top: 50%;
          transform: translate(-50%,-50%);
        }
      }
      .action {
        flex: 1;
        margin-left: 15px;
        height: 100%;
      }
      &:last-child {
        margin-top: 5px;
      }
    }
    &.show {
      transform: translateY(0);
    }
  }
}
</style>